package cuppics;

import org.junit.Test;

public class Prj9 {

	/**
	 * A Pythagorean triplet is a set of three natural numbers, a < b < c, for
	 * which,
	 * 
	 * a2 + b2 = c2 For example, 32 + 42 = 9 + 16 = 25 = 52.
	 * 
	 * There exists exactly one Pythagorean triplet for which a + b + c = 1000.
	 * Find the product abc.
	 */
	@Test
	public void test() {
		int[] abc = getABC(1000);
		System.out.println("a=" + abc[0] + " ,b=" + abc[1] + " ,c=" + abc[2]);
		System.out.println("abc = " + abc[0] * abc[1] * abc[2]);
	}

	public int[] getABC(int num) {

		int[] ret = new int[3];

		for (int i = 1; i < num; i++) {

			for (int j = i + 1; j < num; j++) {

				for (int k = j + 1; k < num; k++) {

					if ((i * i + j * j == k * k) && (i + j + k == 1000)) {
						ret[0] = i;
						ret[1] = j;
						ret[2] = k;
						return ret;
					}
				}
			}
		}
		return ret;
	}

}
